import javax.tools.JavaCompiler;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import java.io.*;
import java.util.Arrays;
import java.lang.Runtime;
import java.lang.reflect.*;

public class Compile
{
	public static void main(String args[])
	{
		try 
		{
			JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
			
			StandardJavaFileManager sjfm = jc.getStandardFileManager(null, null, null);
			
			File javacode = new File("Number.java");

			Iterable<? extends javax.tools.JavaFileObject> codeObject = sjfm.getJavaFileObjects(javacode);
			String[] options = new String[] {"-d","./temp"};
			jc.getTask(null, sjfm, null, Arrays.asList(options), null, codeObject).call();
			
			//Java 6 Platform Revealed by John Zukowski
			//Class.forName("Number").getDeclaredMethod("main",
			//		  new Class[] {String[].class}).invoke(null, new Object[] {null});
			
			//Class.forName("Number").getDeclaredMethod("main", 
			//		new Class[] {String[].class}).invoke(null, new Object[] {"1"});
			/*
	           Class cls = Class.forName("Number"); //Name of the class to load

	            Method meth = cls.getMethod( //Name of method, and its argument
	              "main", String[].class);
	            Object arglist[] = new Object[1]; //Argument list for method
	            arglist[0] = new String[] {"37"};
	            meth.invoke(null, arglist);
			*/
			sjfm.close();

			
		} 
		catch (Exception e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
	}
}
